/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.app.model;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.Map;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Transient;

/**
 *
 * @author LamLe
 */
@Entity
public class M_WebsiteAccount extends M_ValueObject implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(unique = true)
    private String domainName;
    private String userName;
    private String password;
    @Column(length = 100000)
    private String cookies;
    @Transient
    private Map<String, String> cookie;
    private Boolean active;
    @Transient
    private Gson gson;

    public M_WebsiteAccount() {
        gson = new Gson();
    }

    public Map<String, String> getCookie() {
        Type cookieType = new TypeToken<Map<String, String>>() {
        }.getType();
        return gson.fromJson(cookies, cookieType);
    }

    public void setCookie(Map<String, String> cookie) {
        this.cookie = cookie;
    }

    public String getCookies() {
        return cookies;
    }

    public void setCookies(String cookies) {
        this.cookies = cookies;
    }

    public void setCookies(Map<String, String> cookie) {
        this.cookies = gson.toJson(cookie);
    }

    public Boolean getActive() {
        return active;
    }

    public void setActive(Boolean active) {
        this.active = active;
    }

    public String getDomainName() {
        return domainName;
    }

    public void setDomainName(String domainName) {
        this.domainName = domainName;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof M_WebsiteAccount)) {
            return false;
        }
        M_WebsiteAccount other = (M_WebsiteAccount) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.app.model.M_WebsiteAccount[ id=" + id + " ]";
    }
}
